< previous page page_389 next page >

Page 389
One thing you might notice as you first create an MDI application is that the child form, when first shown at runtime, is probably sized differently than it was when you created it (see Figure 17.10). The reason is that Windows, by default, assigns a certain size and position to each MDI child form that is shown.
0389-01.jpg
Figure 17.10
MDI applications automatically size and position their child forms.
If the default size and position are not acceptable to you, you need to place code in the Load event procedure of the child form to position and size it the way you want. To determine the desired size of the child form, check the Height and Width properties of the form while you are in design mode, and then add code to the form's Load event procedure to set the Height and Width properties to their original values. The same concept applies to the position of the form. You can set the Top and Left properties of the child form to set its position. The code in Listing 17.1 shows how to set the size of a child form and center it within the parent form.
note.gif If a child window's size becomes too large for its parent, whether by user action or through code, the parent's size is not changed automatically. The parent does, however, automatically show scrollbars when needed (assuming the ScrollBars property is True), as mentioned in the section "Setting Up a Parent Form" earlier in this chapter. square.gif

Listing 17.1 MDIDEMO2.FRMUse Code to Size and Position the Child Form
Private Sub Form_Load()
    Me.Height = 2745
    Me.Width = 3690
    Me.Top = (mdiMain.ScaleHeight - Me.Height) / 2
    Me.Left = (mdiMain.ScaleWidth - Me.Width) / 2
End Sub
Figure 17.11 shows the effect of this code.
note.gif You cannot use the StartUpPosition property to set the initial position of a child form in an MDI window. In fact, you cannot change the setting of the property for an MDI child form from its default value of 0 - Manual. square.gif

 
< previous page page_389 next page >